﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;
using System.Data.Entity.ModelConfiguration.Configuration;
using WebStore.Domain.Entities.Enum;
namespace WebStore.Domain.Entities.Model
{
    public class Order
    {
        public int Id { get; set; }

        public DateTime OrderDate { get; set; }

        public DateTime? RealizeDate { get; set; }

        public OrderStatus OrderStatus { get; set; }

        public int UserId { get; set; }
        public virtual User User { get; set; }

        public int ?RealizedById { get; set; }
        public virtual User RealizedBy { get; set; }

        public virtual ICollection<OrderDetail> OrderDetails { get; set; } 
    }

    public class OrderConfiguration:EntityTypeConfiguration<Order>
    {
        public OrderConfiguration()
        {
            HasRequired(x => x.User).WithMany().HasForeignKey(x => x.UserId).WillCascadeOnDelete(false);
            HasOptional(x => x.RealizedBy).WithMany().HasForeignKey(x => x.RealizedById).WillCascadeOnDelete(false);
        }
    }
}
